package com.baor.web.controller.finance;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baor.finance.domain.TFlow;
import com.baor.finance.domain.TotleFlow;
import com.baor.finance.service.ITFlowService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baor.common.annotation.Log;
import com.baor.common.core.controller.BaseController;
import com.baor.common.core.domain.AjaxResult;
import com.baor.common.enums.BusinessType;

import com.baor.common.utils.poi.ExcelUtil;
import com.baor.common.core.page.TableDataInfo;

/**
 * 财务流水Controller
 * 
 * @author ruoyi
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/flow/flow")
public class TFlowController extends BaseController
{
    @Autowired
    private ITFlowService tFlowService;

    //查询总收款、总退款、总转账。
    @GetMapping("/total3")
    public AjaxResult flowAmass (){
        return success(tFlowService.flowAmass());
    }

    /**
     * 查询财务流水列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flow:list')")
    @GetMapping("/list")
    public TableDataInfo list(TFlow tFlow)
    {
        startPage();
        List<TFlow> list = tFlowService.selectTFlowList(tFlow);
        return getDataTable(list);
    }

    /**
     * 导出财务流水列表
     */
    @PreAuthorize("@ss.hasPermi('flow:flow:export')")
    @Log(title = "财务流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TFlow tFlow)
    {
        List<TFlow> list = tFlowService.selectTFlowList(tFlow);
        ExcelUtil<TFlow> util = new ExcelUtil<TFlow>(TFlow.class);
        util.exportExcel(response, list, "财务流水数据");
    }

    /**
     * 获取财务流水详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:flow:query')")
    @GetMapping(value = "/{flowId}")
    public AjaxResult getInfo(@PathVariable("flowId") Long flowId)
    {
        return success(tFlowService.selectTFlowByFlowId(flowId));
    }

    /**
     * 新增财务流水
     */
    @PreAuthorize("@ss.hasPermi('flow:flow:add')")
    @Log(title = "财务流水", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TFlow tFlow)
    {
        return toAjax(tFlowService.insertTFlow(tFlow));
    }

    /**
     * 修改财务流水
     */
    @PreAuthorize("@ss.hasPermi('flow:flow:edit')")
    @Log(title = "财务流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TFlow tFlow)
    {
        return toAjax(tFlowService.updateTFlow(tFlow));
    }

    /**
     * 删除财务流水
     */
    @PreAuthorize("@ss.hasPermi('flow:flow:remove')")
    @Log(title = "财务流水", businessType = BusinessType.DELETE)
	@DeleteMapping("/{flowIds}")
    public AjaxResult remove(@PathVariable Long[] flowIds)
    {
        return toAjax(tFlowService.deleteTFlowByFlowIds(flowIds));
    }
}
